# == Schema Information
# Schema version: 38
#
# Table name: students
#
#  id                :integer(11)     not null, primary key
#  user_id           :integer(11)
#  school_id         :integer(11)
#  last_name         :string(255)
#  first_name        :string(255)
#  gender            :integer(11)
#  birth             :date
#  enter_school_year :integer(11)
#  notes             :text
#  notes_html        :text
#  created_at        :datetime
#  updated_at        :datetime
#

class Student < ActiveRecord::Base
  format_attribute :notes
  
  belongs_to :school
  belongs_to :user
  
  has_many :photos
  
  validates_presence_of :school_id, :first_name, :last_name, :gender, :enter_school_year
  validates_numericality_of :enter_school_year
  
  def gender_for_human
    if gender == 0
      "男"
    elsif gender == 1
      "女"
    end
  end
  
  def birth_for_human
    "#{birth.year}年#{birth.month}月#{birth.day}日"
  end
  
  def full_name
    "#{last_name} #{first_name}"
  end
end
